package stack;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

public class Test {
    class Solution{
        public static boolean isValid(String s) {
            if(s.length() % 2 == 1){
                return false;
            }
            // 遍历字符串
            Stack<Character> stack = new Stack<>();
            for(int i = 0; i < s.length(); i++){
                char ch = s.charAt(i);
                if(ch=='(' || ch=='[' ||ch=='{'){
                    stack.push(ch);
                }else{
                    if(stack.empty()){
                        return false;
                    }
                    char match = stack.pop();
                    switch(match){
                        case '(':
                            if(ch==']' ||ch=='}'){
                                return false;
                            }
                            break;
                        case '{':
                            if(ch==')'||ch==']'){
                                return false;
                            }
                            break;
                        case '[':
                            if(ch=='}'||ch==')'){
                                return false;
                            }
                            break;
                    }


                }
            }
            return stack.empty();


        }
    }

    public static void main(String[] args) {
        Queue<Integer>  queue = new LinkedList<>();
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);

        int ret = queue.peek();
        System.out.println(ret);//1
        ret = queue.poll();
        System.out.println(ret);//1
        ret = queue.poll();
        System.out.println(ret);//2
    }

    public static void main2(String[] args) {
        String s = "(]";
        boolean valid = Solution.isValid(s);
        System.out.println(valid);


        MyStack stack = new MyStack();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);

        Integer ret = stack.pop();
        System.out.println(ret);

        ret = stack.peek();
        System.out.println(ret);
        ret = stack.peek();
        System.out.println(ret);

    }
    public static void main1(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);

        Integer ret = stack.pop();
        System.out.println(ret);

        ret = stack.peek();
        System.out.println(ret);
        ret = stack.peek();
        System.out.println(ret);


    }
}
